﻿using System;
using System.Collections.Generic;
using MTC.Common.DTO;
using MTC.Web.Business.DTO;
using MTC.Business.Taxi;
using Taxi=MTC.Business.Taxi.Taxi;

namespace MTC.Web.Business
{
    public class Taxis
    {
        private List<TaxiEntity> _taxiEntityList = new List<TaxiEntity>();
        
        public List<TaxiEntity> GetTaxis()
        {
            List<MTC.Common.DTO.Taxi> taxis;
            taxis = Taxi.GetTaxis();
            if (taxis == null)
                return null;
            _taxiEntityList.Clear();
            foreach (MTC.Common.DTO.Taxi taxi in taxis)
            {
                TaxiEntity entity = new TaxiEntity();
                entity.TaxiId = taxi.TaxiId;
                entity.PlateId = taxi.PlateId;
                entity.PlateNumber = taxi.PlateNumber;
                entity.VehicleId = taxi.VehicleId;
                entity.VehicleRego = taxi.VehicleRego;
                _taxiEntityList.Add(entity);
            }
            return _taxiEntityList;
        }

        public TaxiEntity GetATaxi(int taxiid )
        {
            if (taxiid == 0)
                return null;
            TaxiEntity entity = null;
            MTC.Common.DTO.Taxi taxi = Taxi.GetTaxi(taxiid);
            if (taxi != null)
            {
                entity = new TaxiEntity();
                entity.PlateId = taxi.PlateId;
                entity.TaxiId = taxi.TaxiId;
                entity.VehicleId = taxi.VehicleId;
                entity.PlateNumber = taxi.PlateNumber;
                entity.VehicleRego = taxi.VehicleRego;
            }
            return entity;
        }

        public bool UpdateATaxi(TaxiEntity entity)
        {
            if (entity==null)
            {
                return false;
            }
            MTC.Common.DTO.Taxi taxi = new Common.DTO.Taxi();

            taxi.PlateId = entity.PlateId;
            taxi.TaxiId = entity.TaxiId;
            taxi.VehicleId = entity.VehicleId;
            taxi.PlateNumber = entity.PlateNumber;
            taxi.VehicleRego = entity.VehicleRego;

            return Taxi.UpdateTaxi(taxi);


        }

        public bool DeleteATaxi(int TaxiId)
        {
            if (TaxiId == 0)
                return false;

            return Taxi.DeleteTaxi(TaxiId);
        }

        public int AddTaxi(TaxiEntity entity)
        {
            if (entity == null)
            {
                return 0;
            }
            MTC.Common.DTO.Taxi taxi = new Common.DTO.Taxi();

            taxi.PlateId = entity.PlateId;
            taxi.TaxiId = entity.TaxiId;
            taxi.VehicleId = entity.VehicleId;
            taxi.PlateNumber = entity.PlateNumber;
            taxi.VehicleRego = entity.VehicleRego;

            return Taxi.AddTaxi(taxi);
        }
    }
}
